<?
           if(!isset($SHOW_NOT_FOUND))
           {
                $SHOW_NOT_FOUND = "yes";                                  
           }             

           function expandMyCategories($categoryID,$parentID,$path)
           {
	    	     OB_START();
             ?>
               expand('tr<?=$categoryID?>','img<?=$categoryID?>');                          
             <?
             if($parentID!=0)
             {
               $category = new CategoryBO();
               $category->visible = 1;
               $category->id = $parentID;
               $category->Load(0,1);
               if($category->Next())
               {
                 $category_lang = new CategoryLangBO();
                 $category_lang->langID = CURRENT_LANGUAGE_ID;
                 $category_lang->id = $categoryID;
                 $category_lang->Load(0,1);
                 $category_lang->Next();
                 //fix
                 //$path = expandMyCategories($category->id,$category->parent,$path)." / ".$category_lang->name;
                 $path = $category_lang->name;
                 expandMyCategories($category->id,$category->parent,$path);
               }
             }else
             {
               $category = new CategoryBO();
               $category->visible = 1;
               $category->id = $categoryID;
               $category->Load(0,1);
               if($category->Next())
               {
                 $category_lang = new CategoryLangBO();
                 $category_lang->langID = CURRENT_LANGUAGE_ID;
                 $category_lang->id = $categoryID;
                 $category_lang->Load(0,1);
                 $category_lang->Next();
                 //fix
                 //$path = $category_lang->name.$path;
                 $path = $category_lang->name;
               }             
             }
    		     OB_END_CLEAN();
             return $path;
           }   
                      
           function expandMyMenu($pageID)
           {
		         OB_START();
             $category = new CategoryBO();
             $category->visible = 1;
             $category->pageID = $pageID;
             $category->Load(0,1);
             $path = "";
		         OB_END_CLEAN();
             if($category->Next())
             {
               $path = expandMyCategories($category->id,$category->parent,"");
               expandMyCategories($category->id,$category->parent,"");
             }
             return $path;
           }
           
//---------------------------//---------------------------//---------------------------
           
      if (!isset($PAGE_LOADED)) 
      {
         $page = new PageBO();
         $page->visible = 1;
         if(isset($PAGE_CODE) && strlen($PAGE_CODE)>0)
         {
            $page->code = $PAGE_CODE;           
         }else if(isset($PAGE_ID) && strlen($PAGE_ID)>0)
         {
            $page->id = $PAGE_ID;
         }else
         {
	         if($SHOW_NOT_FOUND!="no")
	         {
	             echo "<b>".$lang["PAGE_NOT_FOUND"]."</b>"; 
	         }
         }

		 OB_START();
		 $page->Load(0,0);
		 OB_END_CLEAN();
      }
       
      if($page->code == "POIP")
      {
         include_once('zamena_poip.php');
      }else
      {
         include_once('zamena.php');
      } 

      if((isset($PAGE_LOADED)&&$PAGE_LOADED)||(!isset($PAGE_LOADED)&&$page->Next()))
      {
         //$menu_path = expandMyMenu($page->id);
         $menu_path = $page->title;
         if(strlen($menu_path))
         {
?>  		<table width="100%" border=0 cellpadding=0 cellspacing=0><tr>
<?
        if(isset($_SESSION["IS_ADM_EDIT"])AND($_SESSION["IS_ADM_EDIT"]=="123456")){
            ?><input admin="1" type="button" value="Edit page" style="top:0px; right:0px; display:block; position:relative; border: 0; z-index: 1001;" src="<?=HTTP_SERVER;?>/images/edit_button.gif" alt="Edit article" onclick="window.open('<?echo(HTTP_SERVER."/admin/main.php?edit_page=page-edit.php&pageID=".$page->id);?>','','');" border="0" ><?
        }

?>
        <td align=left><div class="pagetitle"><?=$menu_path?></div></td></tr></table>
<?  
         }
               $_SESSION["last_page_id"] = $page->id;
               $articles_count = 0; 
               $assign  = new AssignBO();
               $assign->pageID = $page->id;

               if($page->perpage==0)
               {
                 //Load all articles
			           OB_START();
                 $assign->Load(0,0,array($assign->fields["position"] => "0"));
			           OB_END_CLEAN();
               }else if($page->perpagetype == $page->PER_PAGES)
               {
                 //Load  articles by pages
                 $p = POSTGET("p");    
                 if(!is_numeric($p))
                 {
                   $p = 0;
                 } 
			           OB_START();
                 $count = $assign->getCount();
			           OB_END_CLEAN();
?>
<form action="page.php" method="post" name="HiddenForm" id="HiddenForm" >
<input type="hidden" name="id" id="id" value="<?=$page->id?>">
<input type="hidden" name="p" id="p" value="<?=$p?>">
<?
                 require_once("includes/pagers.php");
			           OB_START();
                 $assign->Load($p*$page->perpage,$page->perpage,array($assign->fields["position"] => "0"));
			           OB_END_CLEAN();
               }else if($page->perpagetype == $page->ONLY_FIRST_PAGE)
               {
                 //Load  firts page
			           OB_START();
                 $assign->Load(0,$page->perpage,array($assign->fields["position"] => "0"));
			           OB_END_CLEAN();
               }else if($page->perpagetype == $page->ONLY_LAST_PAGE)
               {
                 //Load  last page
			           OB_START();
                 $assign->Load(0,$page->perpage,array($assign->fields["position"] => "1"));
			           OB_END_CLEAN();
               }
               if($page->perpage!=0 && $page->perpagetype == $page->PER_PAGES)
               {
                 print show_pages_line($page->perpage,$count,$p, 'javascript:document.forms.HiddenForm.elements.p.value="',
	               '";document.HiddenForm.submit();', "");
               }
               while($assign->Next())
               {
                 $ARTICLE_ID = $assign->articleID;
                 include('includes/showarticle.php');
                 ?><?
                 $articles_count++;  
               }
               
               if($page->perpage!=0 && $page->perpagetype == $page->PER_PAGES)
               {
                 print show_pages_line($page->perpage,$count,$p, 'javascript:document.forms.HiddenForm.elements.p.value="',
	               '";document.HiddenForm.submit();', "");
                ?>
                   </form>
                <?
               }

        if($articles_count==0)
        {
          	if($SHOW_NOT_FOUND!="no"){ echo "<b>".$lang["ARTICLES_NOT_FOUND"]."</b>"; }
        }
        }else
        {
           	if($SHOW_NOT_FOUND!="no"){ echo "<b>".$lang["PAGE_NOT_FOUND"]."</b>"; }
        }
?>